<?php 
/**
 * 登陆控制器
 * Enter description here ...
 * @author Larry
 *
 */
class LoginAction extends BaseAction
{
	/**
	 * 登陆视图
	 * Enter description here ...
	 */
	public function index()
	{
		$this->display();
	}
	/**
	 * 异步登陆
	 * Enter description here ...
	 */
	public function doLogin()
		{
			//过滤请求数组
			$requestArr = common_html_Arr($_POST);
			
			//校验用户名
			if ( $requestArr['username'] == NULL )
			{
				
				//响应状态
				$response['status'] = 0; 
				
				//响应信息
				$response['info'] = '用户名不能为空';
				
				die(json_encode($response));
				
			}
			
			//校验密码
			if ( $requestArr['password'] == NULL )
			{
			
				//响应状态
				$response['status'] = 0;
			
				//响应信息
				$response['info'] = '密码不能为空';
				
				die(json_encode($response));
			
			}
			
			$consoleModel = new ConsoleModel();
			
			$result = $consoleModel->checkLogin($requestArr['username'], $requestArr['password']);
			
			if ( $result > 0)
			{
				//响应状态
				$response['status'] = 1;
				
				//响应信息
				$response['info'] = '登录成功';
				
				//保存登录信息$result['username']
				$_SESSION['console']['user_name'] =  $result['username'];
				
				$_SESSION['console']['user_id'] =  $result['user_id'];
				
			}
			else
			{
				
				//响应状态
				$response['status'] = 0;
				
				//响应信息
				$response['info'] = '用户名或密码错误';
				
			}
			
			
			die(json_encode($response));
			
		}
}


?>